function doSubmit(form, action){      
	$j(form).action = action; 
	$j(form).submit();  
}

function checkEnter(e, form, action){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e;
		characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
		if (event) {
			e = event;
		}
		characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		doSubmit(form, action); //submit the form
		return false; 
	}
	else{
		return true;
	}

}

function changeBEtoADYear(dateStr){
	//alert(dateStr.value);
	var tokens = dateStr.value.split("/"); // token[0] = day , token[1] = month, token[2] = year
 
	if(tokens[2] > 2400){
		tokens[2] = tokens[2] - 543;
		//alert(tokens[0] + tokens[1] + tokens[2]);
		$j(dateStr).val(tokens[0] + "/" + tokens[1] + "/" + tokens[2]);
	}	
}

function checkDigit(input) {
	if(input.length != 13 ) {
		return false;
	}
	
	var sumValue = 0;
	var c;

	for(var i=0; i<12; i++) {
		c = (input.charAt(i) - '0')*(13-i);
		sumValue = sumValue + c;
		//console.log("i= "+i+" C = "+c+" Sum = "+sumValue+"\n");
	}

	//console.log("Sum = "+sumValue+"\n");
    var d = 11 - (sumValue % 11);
	if (d >= 10) {d = d - 10;}

	//console.log("D = "+d+"\n");
	//console.log("Digit = "+(input[12]-'0')+"\n");
    
	if((input.charAt(12)-'0') == d){
		//console.log("true");
		return true;
	} else {
		//console.log("false");
		return false;
	}
}

/*validate date format ,corrected format is [DD/MM/YYYY , DD/MM/YY, DDMMYYYY, DDMMYY]*/
function isValidDateDDMMYYYY(strDate) {

    var date_Pattern_Leap = /^(((((([0-2][1-9])|([1-3][0-1]))\/(([0][1,3,5,7,8])|([1][0,2])))|((([0-2][1-9])|([1-3][0]))\/(([0][4,6,9])|([1][1])))|((([0-2][1-9])|([1,2][0]))\/(([0][2]))))\/(([1-9][0-9][0-9][0-9])|(([0-9][1-9])|([1-9][0]))))|((((([0-2][1-9])|([1-3][0-1]))(([0][1,3,5,7,8])|([1][0,2])))|((([0-2][1-9])|([1-3][0]))(([0][4,6,9])|([1][1])))|((([0-2][1-9])|([1,2][0]))(([0][2]))))(([1-9][0-9][0-9][0-9])|(([0-0][1-9])|([1-9][0])))))$/i;
    var date_Pattern_nonLeap = /^((((((([0-2][1-9])|([1-3][0-1]))\/(([0][1,3,5,7,8])|([1][0,2])))|((([0-2][1-9])|([1-3][0]))\/(([0][4,6,9])|([1][1])))|(((([0-1][1-9])|([2][0-8]))|([1,2][0]))\/(([0][2]))))\/(([1-9][0-9][0-9][0-9])|(([0-9][1-9])|([1-9][0])))))|((((([0-2][1-9])|([1-3][0-1]))(([0][1,3,5,7,8])|([1][0,2])))|((([0-2][1-9])|([1-3][0]))(([0][4,6,9])|([1][1])))|(((([0-1][1-9])|([2][1-8]))|([1,2][0]))(([0][2]))))(([1-9][0-9][0-9][0-9])|(([0-9][1-9])|([1-9][0])))))$/i;
    var date_Pattern = date_Pattern_Leap;
    var str = new String(strDate);

    var str2 = '2500';
    var strYear = '';
    var datePart;
    if (str.length == 8) {
        var dateSep = /(\/)/;
        if (str.indexOf('/', 0) >= 0) {
            datePart = str.split(dateSep);
            strYear = str2.substring(0, 2).concat(datePart[2]);
        } else {
            strYear = str.substring(4, 8);
        }
    } else if (str.length == 6) {
        strYear = str2.substring(0, 2).concat(str.substring(4, 6));
    } else if (str.length == 10) {
        var dateSep = /(\/)/;
        datepart = str.split('/');
        strYear = datepart[2];
    } else {
        return false;
    }
    
    strYear = parseInt(strYear) - 543;

    if (strYear%4 == 0 && !(strYear%100 == 0 && !(strYear%400 == 0))) {//(eval(strYear % 4) == 0) {
        date_Pattern = date_Pattern_Leap;
    } else {
        date_Pattern = date_Pattern_nonLeap;
    }
    
    
    if (str.length == 8) {
    	if (str.indexOf('/', 0) >= 0) {
    		strDate = str.substring(0,6).concat(strYear);
    	}else
    	{
    		strDate = str.substring(0,4).concat(strYear);
    	}
    }else if (str.length == 6) {
    	strDate = str.substring(0,4).concat(strYear);
    } else if (str.length == 10) {
    	strDate = str.substring(0,6).concat(strYear);
    }

    if (date_Pattern.test(strDate)) {
        return true;
    } else {
        return false;
    }
}

function forceUpperCase() {
	key = window.event.keyCode;
	if ((key > 0x60) && (key < 0x7B))
		window.event.keyCode = key-0x20;
}

function toUpperCase(o) {
	o.value=o.value.toUpperCase();
}
